package disjunction.collections
{
	/**
	 *
	 *
	 * @author Nick Wiggill
	 */
	
	public class CollectionReadOnly
	{
		protected var _items:Array;
		
		public function CollectionReadOnly(items:Array)
		{
			_items = items;
		}

		protected function internalGetItem(item:Object):int
		{
			var result:int = -1;
			for (var i:int = 0; i < _items.length; i++)
			{
				if (_items[i] == item)
				{
					result = i;
					break;
				}
			}
			return result;
		}
		     
         /**
          * Returns true if this Collection contains the specified item.
          *
          * @param item * whose presence in this collection is to be tested.
          *
          * @return Boolean true if this collection contains the specified item.
          */
        public function contains(item:*):Boolean
        {
            return (internalGetItem(item)> -1);
        }
       
         /**
          * Returns an item within the Collection using it's index.
          *
          * @param index location of item within the Collection.
          *
          * @return * reference to item.
          */
        public function getItemAt(index:int):*
        {
            return _items[index];
        }
       
         /**
          * Returns an iterator over the elements in this collection. There are no guarantees concerning
          * the order in which the elements are returned (unless this collection is an instance of some
          * class that provides a guarantee).
          *
          * @return Iterator object that is used to iterate through the collection.
          */
        public function getIterator():Iterator
        {
            return (new Iterator(this));
        }
       
         /**
          * Returns the current length
          *
          * @return int value reflecting the number of items in this Collection.
          */
        public function getLength():int
        {
            return _items.length;
        }
       
         /**
          * Returns true if the Collection is empty.
          *
          * @return Boolean true if Collection is empty.
          */
        public function isEmpty():Boolean
        {
            return (_items.length == 0);
        }

        public function toString():String
        {
            return _items.toString();
        }
	}
}